package com.jade.store.wechat.biz.business.menu;

import com.jade.store.wechat.biz.common.Log;
import com.jade.store.wechat.biz.common.Util;
import com.jade.store.wechat.biz.protocol.menu.MenuGetReq;
import com.jade.store.wechat.biz.protocol.menu.MenuGetRes;
import com.jade.store.wechat.biz.service.menu.MenuGetService;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * User: jinya
 * Date: 2016/12/14
 * Time: 19:38
 * TEL :17701640710   MAIL:2009_jinya@163.com
 * To change this template use File | Settings | File Templates.
 */
public class MenuGetBusiness {
    private MenuGetService _service;
    //打log用
    private static Log log = new Log(LoggerFactory.getLogger(MenuGetBusiness.class));
    //执行结果
    private static String result = "";

    public MenuGetBusiness(String appid) throws IllegalAccessException, ClassNotFoundException, InstantiationException {
        _service = new MenuGetService(appid);
    }

    /**
     * 调用退款业务逻辑
     * @param req 这个数据对象里面包含了API要求提交的各种数据字段
     * @throws Exception
     */
    public MenuGetRes run(MenuGetReq req) throws Exception {
        //API返回的数据
        String resStr;
        long costTimeStart = System.currentTimeMillis();
        log.i("退款查询API返回的数据如下：");
        resStr = _service.request(req);
        long costTimeEnd = System.currentTimeMillis();
        long totalTimeCost = costTimeEnd - costTimeStart;
        log.i("api请求总耗时：" + totalTimeCost + "ms");
        log.i(resStr);
        //将从API返回的XML数据映射到Java对象
        MenuGetRes res = (MenuGetRes) Util.getObjectFromJson(resStr, MenuGetRes.class);
        return res;
    }

    public String getResult() {
        return result;
    }
}
